package com.hhit.bigscreenbackmanage.service.impl.jjgl;

import com.alibaba.fastjson.JSONObject;
import com.hhit.bigscreenbackmanage.entity.jjgl.TJjglFbjsfb;
import com.hhit.bigscreenbackmanage.entity.jjgl.TJjglGcgsJsjshzb;
import com.hhit.bigscreenbackmanage.dao.jjgl.TJjglGcgsJsjshzbDao;
import com.hhit.bigscreenbackmanage.service.jjgl.TJjglGcgsJsjshzbService;
import com.hhit.bigscreenbackmanage.util.PageUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 工程概算，结算，决算汇总表(TJjglGcgsJsjshzb)表服务实现类
 *
 * @author makejava
 * @since 2021-07-21 14:47:04
 */
@Service("tJjglGcgsJsjshzbService")
public class TJjglGcgsJsjshzbServiceImpl implements TJjglGcgsJsjshzbService {
    @Resource
    private TJjglGcgsJsjshzbDao tJjglGcgsJsjshzbDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TJjglGcgsJsjshzb queryById(String id) {
        return this.tJjglGcgsJsjshzbDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @return 对象列表
     */
    @Override
    public Map<String,Object>  queryAllByLimit(JSONObject jsonObject) {
        Map<String,Object> out = new HashMap<>();
        PageUtil page = new PageUtil();
        String pageSize = jsonObject.get("pageSize").toString();
        String pageNo = jsonObject.get("pageNo").toString();
        int count = tJjglGcgsJsjshzbDao.queryAllCount(jsonObject);
        page.pageCount=Integer.parseInt(pageSize);// 每页数
        page.init(count,Integer.parseInt(pageNo));//参数1：总行数，参数2：当前页
        jsonObject.put("rowNum",page.getRowNum());
        jsonObject.put("pageCount",page.getPageCount());
        out.put("page",page);
        out.put("list",tJjglGcgsJsjshzbDao.queryAll(jsonObject));
        return out;
    }

    /**
     * 新增数据
     *
     * @param tJjglGcgsJsjshzb 实例对象
     * @return 实例对象
     */
    @Override
    public TJjglGcgsJsjshzb insert(TJjglGcgsJsjshzb tJjglGcgsJsjshzb) {
        this.tJjglGcgsJsjshzbDao.insert(tJjglGcgsJsjshzb);
        return tJjglGcgsJsjshzb;
    }

    /**
     * 修改数据
     *
     * @param tJjglGcgsJsjshzb 实例对象
     * @return 实例对象
     */
    @Override
    public TJjglGcgsJsjshzb update(TJjglGcgsJsjshzb tJjglGcgsJsjshzb) {
        this.tJjglGcgsJsjshzbDao.update(tJjglGcgsJsjshzb);
        return this.queryById(tJjglGcgsJsjshzb.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.tJjglGcgsJsjshzbDao.deleteById(id) > 0;
    }

    @Override
    public Map<String, Object> getSsDbDpList(JSONObject jsonObject) {
        Map<String,Object> out = new HashMap<>();
        int[] allDy = {500, 220 , 110, 35 ,10};
        String dydj = jsonObject.get("dydj").toString();
        List<String> dyList = new ArrayList<>();
        for (int i = 0; i < allDy.length; i++) {
            if(Integer.parseInt(dydj) > allDy[i]){
                dyList.add(String.valueOf(allDy[i]));
            }
        }
        PageUtil page = new PageUtil();
        String pageSize = jsonObject.get("pageSize").toString();
        String pageNo = jsonObject.get("pageNo").toString();
        int count = tJjglGcgsJsjshzbDao.getSsDbDpListCount(dyList,dydj,page.getRowNum(),page.getPageCount());
        page.pageCount=Integer.parseInt(pageSize);// 每页数
        page.init(count,Integer.parseInt(pageNo));//参数1：总行数，参数2：当前页
        jsonObject.put("rowNum",page.getRowNum());
        jsonObject.put("pageCount",page.getPageCount());
        out.put("page",page);
        out.put("list",tJjglGcgsJsjshzbDao.getSsDbDpList(dyList,dydj,page.getRowNum(),page.getPageCount()));
        return out;
    }

    @Override
    public Map<String, Object> getDataByCityname(JSONObject jsonObject) throws Exception {
        Map<String,Object> out = new HashMap<>();
        int sbdgc = tJjglGcgsJsjshzbDao.getSbdgcByCityname(jsonObject);
        int zdgc = tJjglGcgsJsjshzbDao.getZdgcByCityname(jsonObject);
        int dtgc = tJjglGcgsJsjshzbDao.getDtgcByCityname(jsonObject);
        int ljkg = 0;
        int ljtc = 0;
        List<Map<String,Object>> ljkgtcList =  tJjglGcgsJsjshzbDao.getLjkgtcByCityname(jsonObject);
        for (Map map:ljkgtcList) {
            ljkg = Integer.parseInt(map.get("ljkg").toString());
            ljtc = Integer.parseInt(map.get("ljtc").toString());
        }
        int zsgc = 0;
        int xcry = 0;
        int ejfx = 0;
        int sjfx = 0;
        int csps = tJjglGcgsJsjshzbDao.getCspsByCityname(jsonObject);
        String nmggz = tJjglGcgsJsjshzbDao.getNmggzByCityname(jsonObject);
        int zlcc = tJjglGcgsJsjshzbDao.getZlccByCityname(jsonObject);
//        int zljdjc = tJjglGcgsJsjshzbDao.getZljdjcByCityname(jsonObject);
        int zljdjc = 0;
        int xjsyyzs = 0;
        Map<String,Object> dataMap = new HashMap<>();
        dataMap.put("sbdgc",sbdgc);
        dataMap.put("zdgc",zdgc);
        dataMap.put("dtgc",dtgc);
        dataMap.put("ljkg",ljkg);
        dataMap.put("ljtc",ljtc);
        dataMap.put("zsgc",zsgc);
        dataMap.put("xcry",xcry);
        dataMap.put("ejfx",ejfx);
        dataMap.put("sjfx",sjfx);
        dataMap.put("csps",csps);
        dataMap.put("nmggz",nmggz);
        dataMap.put("zlcc",zlcc);
        dataMap.put("zljdjc",zljdjc);
        dataMap.put("xjsyyzs",xjsyyzs);
        out.put("dataByCity",dataMap);
        return out;
    }
}